// include system scripts that we need
EvaluateSystemScript("screen.js");  // includes FadeIn and FadeOut
EvaluateSystemScript("input.js");
EvaluateScript("spritesets.js");
//EvaluateSystemScript("time.js");

EvaluateScript("systemmenu.js");   // the Menu object (Basicly the same as the system script
EvaluateScript("menu.js");
EvaluateScript("menu2.js");
EvaluateScript("menu3.js");
EvaluateScript("equip.js");
EvaluateScript("shops.js");
EvaluateScript("shops2.js");
EvaluateScript("levels.js");
EvaluateScript("levels2.js");
EvaluateScript("battle.js");
EvaluateScript("fight.js");
EvaluateScript("save.js");
EvaluateScript("load.js");
EvaluateScript("battleitems.js");
EvaluateScript("special.js");
EvaluateScript("wmagic.js");
EvaluateScript("cmagic.js");
EvaluateScript("misc.js");
EvaluateScript("misc2.js");
EvaluateScript("monsters.js");
EvaluateScript("monsterspecials.js");
EvaluateScript("monsterai.js");
EvaluateScript("songs.js");
EvaluateScript("phouse.js");
EvaluateScript("fightgraphic.js");
EvaluateScript("Book.js");
EvaluateScript("randsbattlespecial.js");
//Change how close you have to be to talk to someone
SetTalkDistance(4);

//Load a few sounds into memory...
LoadSound("NEWGAME.WAV");
LoadSound("Nothing.wav");//Town1.mid");
LoadSound("Nothing.wav");//Town1Inside.mid");
LoadSound("click.wav");
LoadSound("Nothing.wav"); //Battle.mid");



// global variables
var Arrow        = LoadImage("arrow.png");
var Font         = LoadFont("main.rfn");
var GradientFont = LoadFont("main_gradient.rfn");
var WindowStyle  = LoadWindowStyle("test.rws");
var TestWindowStyle  = LoadWindowStyle("main.rws");

var InnPrice = new Object;
InnPrice.cost = 100;

var Chest = new Object;

    
var Player = new Object;
Player.MapEnginePres = false;

Player.P1x = 650;
Player.P1y = 490;
Player.P2x = 650;
Player.P2y = 490;
Player.P3x = 650;
Player.P3y = 490;

Player.event2 = 0;
Player.event3 = false;
Player.event4 = false;
Player.event5 = false;
Player.event6 = false;
Player.event7 = 0;
Player.event8 = 0;
Player.event9 = 0;
Player.event10 = 0;
Player.event11 = 0;

Player.tournamentpres = false;
Player.level = 3
Player.exp = 3200;
Player.hp = 150;
Player.maxhp = 150;
Player.mp = 120;
Player.maxmp = 120;
Player.gp = 11000;
Player.chrclass = "1Soldier";
Player.port = "Mainchar.png";
Player.items = Object;
Player.items.potion = 0;
Player.items.hipotion = 0;
Player.items.fullpotion = 0;
Player.items.ether = 0;
Player.items.turboether = 0;
Player.items.elixer = 0;
Player.items.tent = 0;
Player.items.life = 0;
Player.tentsave = false;
Player.equipwep = "Empty";
Player.equiparmour = "Empty";

Player.engage = 60;

var Playerweapons = new Object;
Playerweapons.Dagger = 0;
Playerweapons.Short_Sword = 0;
Playerweapons.Long_Sword = 0;

var Playerwmagic = new Object;
var Playerbmagic = new Object;
var Playercmagic = new Object;
var Playersoldier = new Object;
var Playerbard = new Object;
var Playerranger = new Object;



Playerweapons.temp = "";
Playerweapons.tempcost = 0;
Player.attackdamage = 0; 
Player.tempdef = 0;

Playerweapons.Lh_Armour = 0;
Playerweapons.StudLh_Armour = 0;


Player.temp = "";

//Other Players

var Player2 = new Object;
Player2.pres = false;
Player2.name = "Dagnar"

var Player2wmagic = new Object;
var Player2bmagic = new Object;
var Player2soldier = new Object;
var Player2bard = new Object;
var Player2ranger = new Object;

Player2.hp = 45;
Player2.maxhp = 45;
Player2.mp = 5;
Player2.maxmp = 5;
Player2.str = 28;
Player2.agi = 18;
Player2.mag = 5;
Player2.vit = 20;
Player2.luck = 18;

Player2.chrclass = "Soldier";
Player2.port = "Dagnar.png";
Player2.spriteset = "Dagnar.rss";
Player2.equipwep = "Long Sword";
Player2.equiparmour = "Leather Armour";

Player2.attack = Player2.str + 25;
Player2.defence = Player2.vit + 20;
Player2.mattack = Player2.mag;
Player2.evade = Player2.agi/5;







var Player3 = new Object;
Player3.pres = false
Player3.name = "Vicks"

var Player3wmagic = new Object;
var Player3bmagic = new Object;
var Player3soldier = new Object;
var Player3bard = new Object;
var Player3ranger = new Object;

Player3.hp = 150;
Player3.maxhp = 150;
Player3.mp = 120;
Player3.maxmp = 120;
Player3.str = 30;
Player3.agi = 20;
Player3.mag = 5;
Player3.vit = 20;
Player3.luck = 15;

Player3.chrclass = "Soldier";
Player3.port = "Soldier.png";
Player3.spriteset = "Garret.rss";
Player3.equipwep = "Empty";
Player3.equiparmour = "Empty";

Player3.attack = Player3.str;
Player3.defence = Player3.vit;
Player3.mattack = Player3.mag;
Player3.evade = Player3.agi/5;

//Other

var Personmove = new Object;

//Weapon Stores
var WeaponStore = new Object;

// fades an image in, waits for a keypress, and fades out
function IntroImage(name)
{
//  var image = LoadImage(name);
//  image.blit(0, 0);
//  FlipScreen();
//  FadeFromColor(500, Black);
//  Delay(500);
}


// displays three images in succession
function Intro()
{
// IntroImage("Untitled.png")
}


function game()
{
  Intro();
  MainMenu();
}

// the main menu
function MainMenu()
{
  var image = LoadImage("Untitled.png");
  image.blit(0, 0);

  // create the menu object
  var menu = new Menu();
  menu.arrow           = Arrow;
  menu.font            = GradientFont;
  menu.window_style    = WindowStyle;
  menu.escape_function = Exit;

  // add the commands to it
  menu.addItem("New Game",    NewGame);
  menu.addItem("Resume Game", ResumeGame);
  menu.addItem("Quit",        Exit);

//  while (true) {
  
//    ClearScreen();
    menu.execute(16, 16, 128, 25);

//  }

}


function NewGame()
{
//Sets items, weapons, etc...
Player.tournamentpres = false;
Player.level = 3
Player.exp = 1300;
Player.nextlevel = 1440;

Player.items.potion = 0;
Player.items.hipotion = 0;
Player.items.fullpotion = 0;
Player.items.ether = 0;
Player.items.turboether = 0;
Player.items.elixer = 0;
Player.items.tent = 0;
Player.tentsave = false;
Player.equipwep = "Empty";
Player.equiparmour = "Empty";
Player.weaponeffect = 0;
Player.armoureffect = 0;
Player.mattackeffect = 1;

Player.tentsave = false;
Player.equipwep = "Empty";
Player.equiparmour = "Empty";

Chest.Num0 = false;//Pire Forest
Chest.Num1 = false;
Chest.Num2 = false;
Chest.Num3 = false;//Pire Cave
Chest.Num4 = false;//Tork
Chest.Num5 = false;
Chest.Num6 = false;
Chest.Num7 = false;//Pangara Gate #1
Chest.Num8 = false;//Pangara
Chest.Num9 = false;//Pangara Castle
Chest.Num10 = false;//Pangara Mine
Chest.Num11 = false;//Pangara Cave1
Chest.Num12 = false;
Chest.Num13 = false;
Chest.Num14 = false;
Chest.Num15 = false;
Chest.Num16 = false;//Orex



Playerweapons.Dagger = 0;
Playerweapons.Dirk = 0;
Playerweapons.Short_Sword = 0;
Playerweapons.MithrilKnife = 0;
Playerweapons.ConqudorKnife = 0;

Playerweapons.Long_Sword = 0;
Playerweapons.BroadSword = 0;
Playerweapons.RegalSword = 0;
Playerweapons.MithrilBlade = 0;
Playerweapons.AdamantineBlade = 0;
Playerweapons.LegendSword = 0;

Playerweapons.WoodenStaff = 0;
Playerweapons.BattleStaff = 0;
Playerweapons.MetalStaff = 0;
Playerweapons.MageStaff = 0;

Playerweapons.Lh_Armour = 0;
Playerweapons.StudLh_Armour = 0;
Playerweapons.IronPlate = 0;
Playerweapons.SilverVest = 0;
Playerweapons.SilverPlate = 0;
Playerweapons.SteelPlate = 0;
Playerweapons.BronzeVest = 0;
Playerweapons.BronzePlate = 0;
Playerweapons.MithrilVest = 0;
Playerweapons.MithrilPlate = 0;
Playerweapons.GoldPlate = 0;
Playerweapons.PlatinumPlate = 0;
Playerweapons.AdamantinePlate = 0;
Playerweapons.AncientPlate = 0;
Playerweapons.Cloak = 0;
Playerweapons.CottonRobe = 0;
Playerweapons.SilkRobe = 0;
Playerweapons.DemonPlate = 0;
Playerweapons.AnglicPlate = 0;
Player.weaponthing = "blank"

Player.DPlate = false;
Player.APlate = false;

Playerweapons.temp = "";
Playerweapons.tempcost = 0;

Playerwmagic.cure = false;
Playerwmagic.peep = false;
Playerwmagic.light = false;
Playerwmagic.sleep = false;
Playerwmagic.life1 = false;
Playerwmagic.cure2 = false;
Playerwmagic.regain = false;
Playerwmagic.powerup = false;
Playerwmagic.defup = false;
Playerwmagic.haste = false;
Playerwmagic.slow = false;
Playerwmagic.stop = false;
Playerwmagic.cure3 = false;
Playerwmagic.safe = false;
Playerwmagic.life2 = false;
Playerwmagic.megacure = false;
Playerwmagic.recover = false;
Playerwmagic.curse = false;

Playerbmagic.fire = false;
Playerbmagic.ice = false;
Playerbmagic.lit = false;
Playerbmagic.earth = false;
Playerbmagic.drainhp = false;
Playerbmagic.fire2 = false;
Playerbmagic.ice2 = false;
Playerbmagic.lit2 = false;
Playerbmagic.earth2 = false;
Playerbmagic.drainmp = false;
Playerbmagic.aero = false;
Playerbmagic.water = false;
Playerbmagic.fire3 = false;
Playerbmagic.ice3 = false;
Playerbmagic.lit3 = false;
Playerbmagic.earth3 = false;
Playerbmagic.aera = false;
Playerbmagic.tidelwave = false;
Playerbmagic.metra = false;
Playerbmagic.alpha = false;
Playerbmagic.omega = false;

Player.customnumber = 0;
Player.customlearn = 0;
Player.customlearning = "Nothing";

Player.cmagic = Object;
Player.cmagic.diease = "Diease";
Player.cmagic.dieasepres = false;
Player.cmagic.plague = "Plague";
Player.cmagic.plaguepres = false;
Player.cmagic.flare = "Flare";
Player.cmagic.flarepres = false;
Player.cmagic.explode = "Explode";
Player.cmagic.explodepres = false;
Player.cmagic.explode2 = "Explode 2";
Player.cmagic.explode2pres = false;
Player.cmagic.telekinesis = "Telekinesis";
Player.cmagic.telekinesispres = false;

Player.cmagic.mpregain = "Mp Regain";
Player.cmagic.mpregainpres = false;
Player.cmagic.anglicray = "Holy Beam";
Player.cmagic.anglicraypres = false;
Player.cmagic.multiup = "Multi-Up"
Player.cmagic.multiuppres = false;
Player.cmagic.hold = "Hold"
Player.cmagic.holdpres = false;
Player.cmagic.encounter = "Encounter"
Player.cmagic.encounterpres = false;

Playersoldier.dash = false;
Playersoldier.dualcombo = false;
Playersoldier.sworddrain = false;
Playersoldier.charge = false;
Playersoldier.quadslice = false;

Playerbard.warsong = false;
Playerbard.intimidate = false;
Playerbard.animals = false;
Playerbard.resonance = false;

Playerranger.defup = false;
Playerranger.power = false;
Playerranger.evade = false;
Playerranger.animals = false;
Playerranger.heal = false;
Playerranger.heal2 = false;
Playerranger.heal3 = false;

Player.temp = "";

Player.engage = 60;

//Player2
Player2.pres = false
Player2.name = "Dagnar"

Player2.level = 2
Player2.exp = 1100;
Player2.nextlevel = 1200;

Player2.hp = 45;
Player2.maxhp = 45;
Player2.mp = 5;
Player2.maxmp = 5;
Player2.str = 28;
Player2.agi = 18;
Player2.mag = 5;
Player2.vit = 20;
Player2.luck = 18;

Player2.chrclass = "Soldier";
Player2.port = "Dagnar.png";
Player2.sprite = "Dagnar.rss";
Player2.equipwep = "Long Sword";
Player2.equiparmour = "Leather Armour";
Player2.weaponeffect = 25;
Player2.armoureffect = 20;
Player2.mattackeffect = 1;

Player2.attack = Player2.str + 25;
Player2.defence = Player2.vit + 20;
Player2.mattack = Player2.mag;
Player2.evade = Math.floor(Player2.agi/5);
Player2.weaponthing = "Weapon";

Player2.DPlate = false;
Player2.APlate = false;

Player2bmagic = Object;
Player2bmagic.fire = false;
Player2bmagic.ice = false;
Player2bmagic.lit = false;
Player2bmagic.earth = false;
Player2bmagic.drainhp = false;
Player2bmagic.fire2 = false;
Player2bmagic.ice2 = false;
Player2bmagic.lit2 = false;
Player2bmagic.earth2 = false;
Player2bmagic.drainmp = false;
Player2bmagic.aero = false;
Player2bmagic.water = false;
Player2bmagic.fire3 = false;
Player2bmagic.ice3 = false;
Player2bmagic.lit3 = false;
Player2bmagic.earth3 = false;
Player2bmagic.aera = false;
Player2bmagic.tidelwave = false;
Player2bmagic.metra = false;
Player2bmagic.alpha = false;
Player2bmagic.omega = false;

Player2wmagic = Object;
Player2wmagic.cure = false;
Player2wmagic.peep = false;
Player2wmagic.light = false;
Player2wmagic.sleep = false;
Player2wmagic.life1 = false;
Player2wmagic.cure2 = false;
Player2wmagic.regain = false;
Player2wmagic.powerup = false;
Player2wmagic.defup = false;
Player2wmagic.haste = false;
Player2wmagic.slow = false;
Player2wmagic.stop = false;
Player2wmagic.cure3 = false;
Player2wmagic.safe = false;
Player2wmagic.life2 = false;
Player2wmagic.megacure = false;
Player2wmagic.recover = false;
Player2wmagic.curse = false;

Player2soldier.dash = true;
Player2soldier.dualcombo = false;
Player2soldier.sworddrain = false;
Player2soldier.charge = false;
Player2soldier.quadslice = false;

Player2bard.warsong = false;
Player2bard.intimidate = false;
Player2bard.animals = false;
Player2bard.resonance = false;

Player2ranger.defup = false;
Player2ranger.powerup = false;
Player2ranger.evade = false;
Player2ranger.animals = false;
Player2ranger.heal = false;
Player2ranger.heal2 = false;
Player2ranger.heal3 = false;


//Player3
Player3.pres = false
Player3.name = "Vicks"

Player3.level = 3;
Player3.exp = 1240;
Player3.nextlevel = 1440

Player3.hp = 150;
Player3.maxhp = 150;
Player3.mp = 120;
Player3.maxmp = 120;
Player3.str = 30;
Player3.agi = 20;
Player3.mag = 5;
Player3.vit = 20;
Player3.luck = 15;

Player3.chrclass = "Soldier";
Player3.port = "Soldier.png";
Player3.equipwep = "Empty";
Player3.equiparmour = "Empty";
Player3.weaponeffect = 0;
Player3.armoureffect = 0;
Player3.mattackeffect = 1;


Player3.attack = Player3.str;
Player3.defence = Player3.vit;
Player3.mattack = Player3.mag;
Player3.evade = Player3.agi/5;

Player3.DPlate = false;
Player3.APlate = false;


Player3bmagic = Object;
Player3bmagic.fire = false;
Player3bmagic.ice = false;
Player3bmagic.lit = false;
Player3bmagic.earth = false;
Player3bmagic.drainhp = false;
Player3bmagic.fire2 = false;
Player3bmagic.ice2 = false;
Player3bmagic.lit2 = false;
Player3bmagic.earth2 = false;
Player3bmagic.drainmp = false;
Player3bmagic.aero = false;
Player3bmagic.water = false;
Player3bmagic.fire3 = false;
Player3bmagic.ice3 = false;
Player3bmagic.lit3 = false;
Player3bmagic.earth3 = false;
Player3bmagic.aera = false;
Player3bmagic.tidelwave = false;
Player3bmagic.metra = false;
Player3bmagic.alpha = false;
Player3bmagic.omega = false;

Player3wmagic = Object;
Player3wmagic.cure = false;
Player3wmagic.peep = false;
Player3wmagic.light = false;
Player3wmagic.sleep = false;
Player3wmagic.life1 = false;
Player3wmagic.cure2 = false;
Player3wmagic.regain = false;
Player3wmagic.powerup = false;
Player3wmagic.defup = false;
Player3wmagic.haste = false;
Player3wmagic.slow = false;
Player3wmagic.stop = false;
Player3wmagic.cure3 = false;
Player3wmagic.safe = false;
Player3wmagic.life2 = false;
Player3wmagic.megacure = false;
Player3wmagic.recover = false;
Player3wmagic.curse = false;

Player3soldier.dash = false;
Player3soldier.dualcombo = false;
Player3soldier.sworddrain = false;
Player3soldier.charge = false;
Player3soldier.quadslice = false;

Player3bard.warsong = false;
Player3bard.intimidate = false;
Player3bard.animals = false;
Player3bard.resonance = false;

Player3ranger.defup = false;
Player3ranger.powerup = false;
Player3ranger.evade = false;
Player3ranger.animals = false;
Player3ranger.heal = false;
Player3ranger.heal2 = false;
Player3ranger.heal3 = false;


Monster1.hp = 0;
Monster2.hp = 0;
Monster3.hp = 0;
Monster4.hp = 0;
Monster1.exp = 0;
Monster2.exp = 0;
Monster3.exp = 0;
Monster4.exp = 0;
Monster1.gold = 0;
Monster2.gold = 0;
Monster3.gold = 0;
Monster4.gold = 0;
/* 
PlaySound("Intro.mp3");

IntroText1();
Delay(200);
*/
 for (i = 0; i < 3; i++)
 {
 placeT[i] = 0;
 }
 for (i = 0; i < 10; i++)
 {
 Phouse[i] = 0;
 }

//Start the game!
  PlaySound("NEWGAME.WAV");
  Player2.pres = false;
  Player3.pres = false;
  Player.event2 = 0;
  Player.event3 = false;
  Player.event4 = false;
  Player.event5 = false;
  Player.event6 = false;
  Player.event7 = 0;
  Player.event8 = 0;
  Player.event9 = 0;
  Player.event10 = 0;
  Player.event11 = 0;
  Player.event12 = 0;
  Player.event13 = 0;
  Player.event14 = 0;
  Player.event15 = 0;
  Player.event16 = 0;
  Player.event17 = 0;
  Player.event18 = 0;

  // start in the Character Selection map
  CreatePerson("begin character", "soldier2.rss", false);
  AttachInput("begin character");
  AttachCamera("begin character");
  BindKey(KEY_ESCAPE, "", "");

  
  var map = "Start.rmp";    
  
  if (Player.MapEnginePres == false)
  {
  Player.MapEnginePres = true;
  MapEngine("Start.rmp", 60);  
  }
  else
  {
  ChangeMap("Start.rmp");
  }
}

function GetName()
{
  eatKey();
  var prompt = "Enter player's name: ";
  Font.drawText(8, 8, prompt);
  Player.name = GetString(8 + Font.getStringWidth(prompt), 8, GradientFont);

  if (Player.name == "")
  {
  WindowStyle.drawWindow (25, 380, 590, 80);//25, 330, 590, 130
  Font.drawTextBox (75, 400, 525, 60, 5, "You must select a name!");//75, 380, 525, 100, 5
  Font.drawText(8, 8, prompt);
  FlipScreen();
  Delay(1000);
  eatKey();
//  GetKey();
  GetName();
  }
}


function ResumeGame()
{
TheLoadMenu();
}

function Configure()
{
}

//--------------------------Game Start Code-------------

function ChooseMenu(chrclass, TalkString, port)//Character Class menu
{
  Player.chrclass = chrclass;
  RenderMap() 
  WindowStyle.drawWindow (25, 380, 590, 80);
  Font.drawTextBox (75, 400, 525, 60, 5, TalkString);
  Portrait = LoadImage(port);
  Portrait.blit(30, 400);

  // create the menu object
  var PickMenu = new Menu();
  PickMenu.arrow           = Arrow;
  PickMenu.font            = Font;
  PickMenu.window_style    = WindowStyle;
  PickMenu.escape_function = PickMenuNo;

  // add the commands to it
  PickMenu.addItem("Choose the " + chrclass,     PickMenuYes);
  PickMenu.addItem("Go with someone else",    PickMenuNo );
  PickMenu.execute(220, 290, 200, 20);
  
}

function PickMenuYes()
// Sets stats and spirteset for whatever class was selected
{
  GetName();

  Player.eventstart = 0;
  if (Player.chrclass == "Soldier")
  {
    
    Player.hp = 50;
    Player.maxhp = 50;
    Player.mp = 5;
    Player.maxmp = 5;
    Player.gp = 1000;
    Player.port = "Soldier.png"
    //Other Player Stats
    Player.str = 30;
    Player.agi = 20;
    Player.mag = 5;
    Player.vit = 20;
    Player.luck = 15;    
    Player.sprite = "soldier.rss";

    Player.quest = "Take part in Tork's Tournament";
    Playersoldier.dash = true;
    Playersoldier.dualcombo = false;
    Playersoldier.sworddrain = false;
    Playersoldier.charge = false;
    Playersoldier.quadslice = false;


    // start in the first town map
    CreatePerson("main character", "soldier.rss", false);
    AttachInput("main character");
    AttachCamera("main character");
    DestroyPerson("begin character");
    BindKey(KEY_ESCAPE, "GameMenu()", "");
    ChangeMap("Town1House1.rmp");
    SetPersonLayer("main character", 1);

  }
  else if (Player.chrclass == "Ranger")
  {
    Player.hp = 45;
    Player.maxhp = 45;
    Player.mp = 15;
    Player.maxmp = 15;
    Player.gp = 750;
    Player.port = "Ranger.png"
    //Other Player Stats
    Player.str = 26;
    Player.agi = 24;
    Player.mag = 14;
    Player.vit = 20;
    Player.luck = 15;
    Player.sprite = "Ranger.rss";
    Player.quest = "Clear out the danger in Pire Forest";
    
    // start in the first town map
    CreatePerson("main character", "Ranger.rss", false);
    AttachInput("main character");
    AttachCamera("main character");
    DestroyPerson("begin character");
    BindKey(KEY_ESCAPE, "GameMenu()", "");
    ChangeMap("Town1House1.rmp");
    SetPersonLayer("main character", 1);
     
  } 
  else if (Player.chrclass == "Mage")
  {
    Player.hp = 30;
    Player.maxhp = 30;
    Player.mp = 30;
    Player.maxmp = 30;
    Player.gp = 750;
    Player.port = "Mage.png"
    //Other Player Stats
    Player.str = 17;
    Player.agi = 18;
    Player.mag = 34;
    Player.vit = 17;
    Player.luck = 22;
    Player.sprite = "Mage.rss";
    Player.customlearn = 0;
    Player.customlearning = "Nothing";

    Player.quest = "Deliver herbs to Magnar in Tork";

    Playerwmagic.cure = true;
    Playerwmagic.peep = true;

    Playerbmagic.fire = true;
    Playerbmagic.ice = true;
    Playerbmagic.lit = true;
    
    // start in the first town map
    CreatePerson("main character", "Mage.rss", false);
    AttachInput("main character");
    AttachCamera("main character");
    DestroyPerson("begin character");
    BindKey(KEY_ESCAPE, "GameMenu()", "");
    ChangeMap("Town1House1.rmp");
    SetPersonLayer("main character", 1);
  } 
  else
  {
    Player.hp = 40;
    Player.maxhp = 40;
    Player.mp = 20;
    Player.maxmp = 20;
    Player.gp = 1000;
    Player.port = "Bard.png"
    //Other Player Stats
    Player.str = 22;
    Player.agi = 18;
    Player.mag = 20;
    Player.vit = 19;
    Player.luck = 22;
    Player.sprite = "Bard.rss";

    Player.quest = "Preform at Tork's Tournament";

    Playerwmagic.cure = true;

    Playerbmagic.fire = true;
    Playerbmagic.ice = true;
    Playerbmagic.lit = true;

    Playerbard.warsong = true;
    
    // start in the first town map
    CreatePerson("main character", "Bard.rss", false);
    AttachInput("main character");
    AttachCamera("main character");
    DestroyPerson("begin character");
    BindKey(KEY_ESCAPE, "GameMenu()", "");
    ChangeMap("Town1House1.rmp");
    SetPersonLayer("main character", 1);
  
  }

Player.attack = Player.str;
Player.defence = Player.vit;
Player.mattack = Player.mag;
Player.evade = Math.floor(Player.agi/5);
SetTalkDistance(4);
}

function PickMenuNo()
{
}

function GameStart()
{
	if (Player.eventstart != 1)
	{
	RenderMap();
	FadeIn(500);
	Player.eventstart = 1;
	eatKey();
		if (Player.chrclass == "Soldier")
		{
			Talk_Window("A tournament will be taking place in Tork shortly and you will be competing in it.  Prepare your equipment and set out to Tork.", "blank.png"); 
		}
		else if (Player.chrclass == "Ranger")
		{
			Talk_Window("There have been reports of increased monster activity in the Great Pire Forest lately and it's your job as the local ranger to investigate what's going on.  Before you leave though, buy some equipment and items for your travel.", "blank.png");
		}
		else if (Player.chrclass == "Mage")
		{
			Talk_Window("Master Magner (your previous teacher) has asked you to deliver him some herbs from the Pire Item Shop.  Having gotten these, you now have to buy some equipment and then deliver the herbs to him in Tork.", "blank.png");
		}
		else
		{
			Talk_Window("Your holidays in your hometown have ended and it's now time to travel to Tork and play at the tournament.  Equip yourself and leave for Tork.", "blank.png");
		}
	}
}


//----------------------Misc Game Functions--------------

//Note:  All "eatKey" commands came from Trial and Error

function Inn(price)
{
  InnPrice.cost = price;
  RenderMap() 
  WindowStyle.drawWindow (25, 380, 590, 80);
  Font.drawTextBox (75, 400, 525, 60, 5, "Our current Price is " + price + "Gp");

  // create the menu object
  var InnMenu = new Menu();
  InnMenu.arrow           = Arrow;
  InnMenu.font            = Font;
  InnMenu.window_style    = WindowStyle;
  InnMenu.escape_function = InnmenuNo;

  // add the commands to it
  InnMenu.addItem("Rest",     InnmenuYes);
  InnMenu.addItem("Leave",    InnmenuNo );
  InnMenu.execute(515, 350, 100, 20);
  
}

function InnmenuYes()

{
  if (Player.gp >= InnPrice.cost)
  {
    Player.gp = Player.gp - InnPrice.cost;
    Player.hp = Player.maxhp;
    Player.mp = Player.maxmp;
    Player.day = Player.day + 1;

    if (Player2.pres == true)
    {
      Player2.hp = Player2.maxhp;
      Player2.mp = Player2.maxmp;
    }
    if (Player3.pres == true)
    {
      Player3.hp = Player3.maxhp;
      Player3.mp = Player3.maxmp;
    }

    RenderMap();
    FadeToColor(500, Black);
    Delay(500);
    FadeFromColor(500, Black);
    WindowStyle.drawWindow (100, 330, 440, 50);
    Font.drawTextBox (150, 350, 500, 100, 5, "Hp and Mp restored!");
    FlipScreen();
    Delay(1000)

  }
  else
  {
    Talk_Window("Sorry, but you do not have enough money.", "blank.png");  
  }  
}  

function InnmenuNo()
  {
    Talk_Window("See you later.", "blank.png");  
    Delay(200)
    eatKey();
  }  

//Since most people look at you when you're talking to them... 

function FacePlayer(name)
{
Player.temp = GetPersonDirection(name)

  if (GetPersonDirection("main character") == 0)
  {
  SetPersonDirection(name, 4)
  }
  else if (GetPersonDirection("main character") == 1)
  {
  SetPersonDirection(name, 6)
  }
  else if (GetPersonDirection("main character") == 2)
  {
  SetPersonDirection(name, 6)
  }
  else if (GetPersonDirection("main character") == 3)
  {
  SetPersonDirection(name, 6)
  }
  else if (GetPersonDirection("main character") == 4)
  {
  SetPersonDirection(name, 0)
  }
  else
  {
  SetPersonDirection(name, 2)
  }
}
function DeFacePlayer(name)
{
  SetPersonDirection(name, Player.temp);
} 

//For when you find a chest with money...
function GetGp(amount) //Oops! No longer used.
{
 RenderMap() 
 WindowStyle.drawWindow (100, 330, 440, 50);
 Font.drawTextBox (150, 350, 500, 100, 5, "Recieved " + amount + "GP!");
 FlipScreen();
 Delay(200)
 eatKey();
 Player.gp = Player.gp + amount;
 while (IsKeyPressed(KEY_SPACE) == false) 
 {GetKey()}
}
function Door(layer)
{
Player_x = GetPersonX("main character");
Player_y = GetPersonY("main character");
Player_x_tile = Math.floor(Player_x/16);
Player_y_tile = Math.floor(Player_y/16);
  if (GetTile(Player_x_tile, Player_y_tile-1, layer) == 9)
  {
  }
  else
  {
  PlaySound("click.wav");
  SetTile(Player_x_tile, Player_y_tile-1, layer, 9);
  SetTile(Player_x_tile, Player_y_tile - 2, layer, 8);
  }
}

//--------------Code Edited From "Trial and Error"----------

// makes a nice little talk window.

function Talk_Window(TalkString, port)
{
 var startTime = GetTime();

 RenderMap();
 WindowStyle.drawWindow (25, 380, 590, 80);//25, 330, 590, 130
 Portrait = LoadImage(port);
 Portrait.blit(30, 400);
 Font.drawTextBox (75, 400, 525, 50, 5, TalkString);//75, 380, 525, 100, 5
 FlipScreen();
 eatKey();
	while (true)
	{
		if (GetTime() - startTime > 100 && AreKeysLeft())
		{
			switch (GetKey())
			{
				case KEY_ENTER:
				{
				eatKey();
  			return;
				}
				case KEY_SPACE:
				{
				eatKey();
				return;
				}
			}
		}
	}
}
//eatKey function 
function eatKey()
{
//  while (IsKeyPressed(KEY_SPACE)) { } // or key S!!

  // eat all keys that in the queue 
  while (AreKeysLeft()) { 
  GetKey(); }
}


// Warp function edited from "Trial and Error"
function NewMap(map,newx,newy,newlayer, setdir)
{
RenderMap();
Battle.counter = 0;
FadeToColor(500, Black);
ChangeMap(map);
SetPersonX("main character",newx - 1);
SetPersonY("main character",newy - 1);
SetPersonLayer("main character",newlayer);
  if (setdir >= 0)
  {
  SetPersonDirection("main character", setdir);
  }
SetCameraX(newx - 1);
SetCameraY(newy - 1);
RenderMap();
FadeFromColor(500, Black);
eatKey();
}


/*EVENTS:
Pire:
Player.eventstart
Player.event2
Pire Forest:
Player.event3
*/